package com.kd.mining.lda.core;

import java.util.ArrayList;

import com.kd.utils.FileUtil;


public class ModelParameter {

	private float alpha = 0.5f; //usual value is 50 / K
	private float beta = 0.1f;//usual value is 0.1
	private int topicNum = 100;
	private int iteration = 100;
	private int saveStep = 10;
	private int beginSaveIters = 50;
	
	public ModelParameter() {
		
	}
	public ModelParameter(float alpha, float beta, int topicNum, int iteration, int saveStep, int beginSaveIters) {
		this.alpha = alpha;
		this.beta = beta;
		this.topicNum = topicNum;
		this.iteration = iteration;
		this.saveStep = saveStep;
		this.beginSaveIters = beginSaveIters;
	}
	
	public void init(String fileName) {
		ArrayList<String> paramLines = new ArrayList<String>();
		ClassLoader cl = ModelParameter.class.getClassLoader();
		if(null == cl) {
			return ;
		}
		String path = cl.getResource(fileName).getPath();
		FileUtil.readLines(path, paramLines);
		for(String line : paramLines){
			String[] lineParts = line.split("\t");
			switch(Parameters.valueOf(lineParts[0])){
				case alpha:
					this.alpha = Float.valueOf(lineParts[1]);
					break;
				case beta:
					beta = Float.valueOf(lineParts[1]);
					break;
				case topicNum:
					topicNum = Integer.valueOf(lineParts[1]);
					break;
				case iteration:
					iteration = Integer.valueOf(lineParts[1]);
					break;
				case saveStep:
					saveStep = Integer.valueOf(lineParts[1]);
					break;
				case beginSaveIters:
					beginSaveIters = Integer.valueOf(lineParts[1]);
					break;
				}
		}
	}
	
	public float getAlpha() {
		return alpha;
	}
	public void setAlpha(float alpha) {
		this.alpha = alpha;
	}
	public float getBeta() {
		return beta;
	}
	public void setBeta(float beta) {
		this.beta = beta;
	}
	public int getTopicNum() {
		return topicNum;
	}
	public void setTopicNum(int topicNum) {
		this.topicNum = topicNum;
	}
	public int getIteration() {
		return iteration;
	}
	public void setIteration(int iteration) {
		this.iteration = iteration;
	}
	public int getSaveStep() {
		return saveStep;
	}
	public void setSaveStep(int saveStep) {
		this.saveStep = saveStep;
	}
	public int getBeginSaveIters() {
		return beginSaveIters;
	}
	public void setBeginSaveIters(int beginSaveIters) {
		this.beginSaveIters = beginSaveIters;
	}
	
	public enum Parameters {
		alpha, beta, topicNum, iteration, saveStep, beginSaveIters;
	}
}
